<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>教学班管理</title>
		<!-- Bootstrap Styles-->
		<link href="../../css/bootstrap/bootstrap.css" rel="stylesheet" />
		<!-- FontAwesome Styles-->
		<link href="../../css/font-awesome.css" rel="stylesheet" />
		<!-- Morris Chart Styles-->

		<!-- Custom Styles-->
		<link href="../../css/custom-styles.css" rel="stylesheet" />
		<!-- Google Fonts-->
		<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
		<!-- TABLE STYLES-->
		<link href="../../js/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
	</head>

	<body>
		<div id="wrapper">
			<nav class="navbar navbar-default top-navbar" role="navigation">
				<div class="navbar-header">
					<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
					<a class="navbar-brand" href="tea_course_index.html">题库与考试</a>
				</div>

				<ul class="nav navbar-top-links navbar-right">

					<li class="dropdown">
						<a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
							<i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
						</a>
						<ul class="dropdown-menu dropdown-user">
							<li>
								<a href="../student/stu_person_index.html"><i class="fa fa-user fa-fw"></i> 个人中心</a>
							</li>
							<li class="divider"></li>
							<li>
								<a href="../../login.html"><i class="fa fa-sign-out fa-fw"></i> 退出登录</a>
							</li>
						</ul>
						<!-- /.dropdown-user -->
					</li>
					<!-- /.dropdown -->
				</ul>

			</nav>
			<!--/. NAV TOP  -->
			<nav class="navbar-default navbar-side" role="navigation">
				<div class="sidebar-collapse">
					<ul class="nav" id="main-menu">
						<li>
							<a href="tea_course_index.html"><i class="fa fa-dashboard"></i> 课程管理</a>
						</li>
						<li>
							<a class="active-menu" href="tea_class_index.html"><i class="fa fa-desktop"></i> 教学班管理</a>
						</li>
						<li>
							<a href="tea_kpoint_index.html"><i class="fa fa-bar-chart-o"></i> 知识点管理</a>
						</li>
						<li>
							<a href="#"><i class="fa fa-qrcode"></i> 题库管理<span class="fa arrow"></span></a>
							<ul class="nav nav-second-level">
								<li>
									<a href="tea_itbank_new_index.html">新建题库</a>
								</li>
								<li>
									<a href="tea_itbank_defend_index.html">维护题库</a>
								</li>
								<li>
									<a href="tea_itbank_browse_index.html">查看题库</a>
								</li>
							</ul>
						</li>
						<li>
							<a href="#"><i class="fa fa-sitemap"></i> 试卷管理<span class="fa arrow"></span></a>
							<ul class="nav nav-second-level">
								<li>
									<a href="tea_paper_new_index.html">创建试卷</a>
								</li>
								<li>
									<a href="tea_paper_browse_index.html">查看试卷列表</a>
								</li>
							</ul>
						</li>
						<li>
							<a href="#"><i class="fa fa-fw fa-file"></i> 考试管理<span class="fa arrow"></span></a>
							<ul class="nav nav-second-level">
								<li>
									<a href="tea_test_new_index.html">创建考试</a>
								</li>
								<li>
									<a href="tea_test_alter_index.html">修改考试设置</a>
								</li>
								<li>
									<a href="tea_test_browse_index.html">查看考试情况</a>
								</li>
							</ul>
						</li>
					</ul>

				</div>

			</nav>
			<!-- /. NAV SIDE  -->
			<div id="page-wrapper">
				<div id="page-inner">
					<div class="row">
						<div class="col-md-12">
							<h1 class="page-header">
								教学班管理
								<small>我教的班</small>
								<a href="#mymodal_3" role="button" data-toggle="modal">
									<div  style="display: inline;float: right;">
										<button type="button" class="btn btn-primary">
											+添加班级
										</button>
									</div>
								</a>
                        </h1>
						</div>
					</div>
					<!-- /. ROW  -->

					<div class="row">
						<div class="col-md-12">
							<!-- Advanced Tables -->
							<div class="panel panel-default">
								<div class="panel-heading">
									班级名单
								</div>
								<div class="panel-body">
									<div class="table-responsive">
										<table class="table table-striped table-bordered table-hover" id="class">
											<thead>
												<tr>
													<th>教学班名称</th>
													<th>学年</th>
													<th>学期</th>
													<th>上课地点</th>
													<th>操作</th>
												</tr>
											</thead>
											<tbody>

											</tbody>
										</table>
									</div>

								</div>
							</div>
							<!--End Advanced Tables -->
						</div>
					</div>
					<!-- /. ROW  -->
				</div>
				<!-- /. PAGE INNER  -->

			</div>
			<!-- 模态框1  -->
			<div class="modal fade" id="mymodal_1" tabindex="-1" role="dialog" aria-labelledby="myModelLabel"
				 aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="myModal_1Label">
								修改教学班信息
							</h4>
						</div>
						<div class="modal-body">
							<div class="modal-body">
								<label for="className">教学班名称</label>
								<input type="text" class="form-control" id="updateClassName">
								<label for="classAddr">上课地点</label>
								<input type="text" class="form-control" id="updateClassAddr">
								<label for="classYear">上课学年</label>
								<input type="number" class="form-control" id="updateClassYear">
								<label for="classTerm">学期</label>
								<select name="" id="updateClassTerm" class="form-control">
									<option value="1">第一学期</option>
									<option value="2">第二学期</option>
									<option value="3">短学期</option>
								</select>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭
							</button>
							<button type="button" class="btn btn-primary" id="updateClassInformation">
								提交更改
							</button>
						</div>
					</div>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>
			<!-- 删除班级信息 -->
			<!-- 模态框2 -->
			<div class="modal fade" id="mymodal_2" tabindex="-1" role="dialog" aria-labelledby="myModelLabel" aria-hidden="true">
				<div class="modal-dialog">
					<form class="modal-content" id="classForm2" method="get">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="myModal_2Label">
								是否删除?
							</h4>
						</div>
						<div class="modal-body">
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">
								关闭
                            </button>
							<button type="submit" class="btn btn-danger" id="deleteClass">
								删除
							</button>
						</div>
					</form>
					<!-- /.modal-content -->
				</div>
				<!-- /.modal -->
			</div>
			<!-- 模态框3 -->
			<!-- 模态框3 -->
			<div class="modal fade" id="mymodal_3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<form class="modal-content" id="classForm" method="post">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								&times;
							</button>
							<h4 class="modal-title" id="myModal_3Label">
								添加班级
							</h4>
						</div>
						<div class="modal-body">
							<label for="className">教学班名称</label>
							<input type="text" class="form-control" id="className">
							<label for="classAddr">上课地点</label>
							<input type="text" class="form-control" id="classAddr">
							<label for="classYear">上课学年</label>
							<input type="number" class="form-control" id="classYear">
							<label for="classTerm">学期</label>
							<select name="" id="classTerm" class="form-control">
								<option value="1">第一学期</option>
								<option value="2">第二学期</option>
								<option value="3">短学期</option>
							</select>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭
							</button>
							<button type="submit" class="btn btn-primary" id="addClassBtn">
								添加班级
							</button>
						</div>
					</form>
				</div>
				<!-- /.modal-content -->
			</div>

			<!-- 使用ajax实现删除 -->
			<!-- /. PAGE WRAPPER  -->
			<!-- /. WRAPPER  -->
			<!-- JS Scripts-->
			<!-- jQuery Js -->
			<script src="../../js/jquery-1.10.2.js"></script>
			<!-- Bootstrap Js -->
			<script src="../../js/bootstrap.min.js"></script>
			<!-- Metis Menu Js -->
			<script src="../../js/jquery.metisMenu.js"></script>
			<!-- DATA TABLE SCRIPTS -->
			<script src="../../js/dataTables/jquery.dataTables.js"></script>
			<script src="../../js/dataTables/dataTables.bootstrap.js"></script>
			<script src="../../js/jquerysession.js"></script>
			<!-- /.modal -->

			<!-- 页面用户名校验 -->
			<script>
				var classId;
                $(document).ready(function () {
                    if ($.session.get('userid') == null) {
                        alert("请先登录！！！");
                        window.location.href = '/login.html';
                    } else {
                        if ($.session.get('usertype') != 1) {
                            alert("您没有访问这个页面的权限！！！");
                            window.location.href = '/login.html';
                        }else{
                            $.ajax({
								type:'get',
								url:'/CourseTeacher/findByTeacherid/'+$.session.get('userid'),
								dataType:'json',
								success:function (data) {
									$.each(data.data,function (index,obj) {
										$("#class").append('<tr><td>'+obj.nickname+'</td>' +
											'<td>'+ obj.year+'</td>' +
											'<td>'+ obj.term+'</td>' +
											'<td>'+ obj.address +'</td>' +
											'<td>' +
                                            '<button data-target="#mymodal_1" class="btn btn-primary" data-toggle="modal" onclick="updateClass(' + obj.id + ');ClassId('+obj.id+')">修改</button>' +
                                        	'<button data-target="#mymodal_2" class="btn btn-danger" data-toggle="modal" onclick="ClassId(' + obj.id + ')">删除</button>' +
											'</td>' +
											'</tr>');
                                    })
                                }
							})
						}
                    }
                });

                $("#deleteClass").click(function (e) {
                    e.preventDefault();
                    $.ajax({
                        type:'get',
						url:'/CourseTeacher/delete/'+courseId,
						dataType:'json',
						success:function (data) {
							if (data.msg == "success"){
							    alert("删除成功");
							}else{
							    alert(data.msg);
							}
							window.location.href="tea_class_index.html";
                        }
                    })
                });

                $("#addClassBtn").click(function (e) {
                    e.preventDefault();
					var className = $("#className").val();
					var classAddr = $("#classAddr").val();
					var classYear = $("#classYear").val();
					var classTerm = $("#classTerm").val();
					if (className == "" || classAddr == "" || classYear == ""){
					    alert("请输入必要的信息");
					}else{
					    var clazz = JSON.stringify({"nickname":className,"address":classAddr,"year":classYear,"term":classTerm,"teacherid":$.session.get("userid")});
					    $.ajax({
							type:'post',
							url:'/CourseTeacher/add',
							data:clazz,
							contentType:'application/json',
							dataType:'json',
							success:function (data) {
								if (data.msg == "success"){
								    alert("添加教学班成功");
								}else{
								    alert(data.msg);
								}
								window.location.href="tea_class_index.html";
                            }
						})
					}
                });

				$("#updateClassInformation").click(function (e) {
                    e.preventDefault();
                    var className = $("#updateClassName").val();
                    var classAddr = $("#updateClassAddr").val();
                    var classYear = $("#updateClassYear").val();
                    var classTerm = $("#updateClassTerm").val();
                    if (className == "" || classAddr == "" || classYear == ""){
                        alert("请输入必要的信息");
                    }else{
                        var clazz = JSON.stringify({"id":classId,"nickname":className,"address":classAddr,"year":classYear,"term":classTerm});
                        $.ajax({
                            type:'post',
                            url:'/CourseTeacher/update',
                            data:clazz,
                            contentType:'application/json',
                            dataType:'json',
                            success:function (data) {
                                if (data.msg == "success"){
                                    alert("修改教学班信息成功");
                                }else{
                                    alert(data.msg);
                                }
                                window.location.href="tea_class_index.html";
                            }
                        })
                    }
                });

				function ClassId(id){
					classId = id;
					console.log(classId);
				}
				
				function updateClass(id) {
					$.ajax({
						type:'get',
						url:'/CourseTeacher/findById/'+id,
						dataType:'json',
						success:function (data) {
						    $("#updateClassName").val(data.data.nickname);
                            $("#updateClassAddr").val(data.data.address);
                            $("#updateClassYear").val(data.data.year);
                            $("#updateClassTerm").val(data.data.term);
                        }
					})
                }
			</script>
		</div>
	</body>
</html>